import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import { fileURLToPath, URL } from "node:url"
import { loadEnv } from "vite"
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const root = process.cwd();
  return {
    plugins: [vue()],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    css: {
      // css预处理器
      preprocessorOptions: {
        less: {
          charset: false,
          additionalData: '@import "./src/assets/style/global.less";',
        },
      },
    },
    server: {
      proxy: {
        '/api': {
          // “/api” 以及前置字符串会被替换为真正域名
          target: 'http://localhost:3000/', // 请求域名
          secure: false, // 请求是否为https
          changeOrigin: true, // 是否跨域
          rewrite: path =>
            path.replace(/^\/api/, ""),
        },
      },
    },
  }
})
